package com.jason.kotlin.meta.architecture2.ui.adapter

import android.content.res.ColorStateList
import android.os.Build
import android.text.Html
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.RequiresApi
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.jason.kotlin.meta.R
import com.jason.kotlin.meta.architecture2.model.ArticleBean

class ProjectArticleAdapter(resId: Int) : BaseQuickAdapter<ArticleBean, BaseViewHolder>(resId),
    LoadMoreModule {


    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    override fun convert(holder: BaseViewHolder, item: ArticleBean) {
        item.apply {
            holder.setText(R.id.item_project_author, if (author.isNotEmpty()) author else shareUser)
            holder.setText(R.id.item_project_title, Html.fromHtml(title))
            holder.setText(R.id.item_project_content, Html.fromHtml(desc))
            holder.setText(R.id.item_project_type, Html.fromHtml("$superChapterName·$chapterName"))
            holder.setText(R.id.item_project_date, niceDate)
            val color = if(collect) {
                holder.itemView.resources.getColor(R.color.accent)
            }else{
                holder.itemView.resources.getColor(R.color.color_white_d8d8d8)
            }
            holder.getView<ImageView>(R.id.item_project_collect).imageTintList = ColorStateList.valueOf(color)

            //展示标签
            holder.setGone(R.id.item_project_new, fresh)
            holder.setGone(R.id.item_project_top, type == 1)
            if (tags.isNotEmpty()) {
                holder.setGone(R.id.item_project_type1, true)
                holder.setText(R.id.item_project_type1, tags[0].name)
            } else {
                holder.setGone(R.id.item_project_type1, false)
            }
        }



        holder.getView<ImageView>(R.id.item_project_collect).setOnClickListener {

        }

        holder.getView<TextView>(R.id.item_project_author).setOnClickListener {
//            if (clickable) {
//                mContext.startActivity(Intent(mContext, ShareByIdActivity::class.java).apply {
//                    putExtra("id", item?.userId)
//                })
//            }
        }
    }

}